# Set the binary name and version
BINARY_NAME := device
VERSION := 0.1.0

# Set the default architecture
ARCH ?= x86
OS ?= linux

# Set the flags for each architecture
ifeq ($(ARCH),arm)
    GOARCH := arm64
    LDFLAGS := -w -s -X main.version=$(VERSION)
else
    GOARCH := amd64
    LDFLAGS := -w -s -X main.version=$(VERSION)
endif

# Set the build directory
BUILD_DIR := .
DIST_DIR := .

.PHONY: all clean x86 arm win

all: $(BUILD_DIR)/$(BINARY_NAME)

$(BUILD_DIR)/$(BINARY_NAME): *.go
	@echo "Building $(BINARY_NAME) for $(ARCH)..."
	go mod tidy
	env GOOS=$(OS) GOARCH=$(GOARCH) go build -o $@ -ldflags "$(LDFLAGS)"

clean:
	@echo "cleaning up..."
	rm -rf $(BUILD_DIR)/$(BINARY_NAME)

win:
	@$(MAKE) ARCH=x86 OS=windows

x86:
	@$(MAKE) ARCH=x86 OS=linux

arm:
	@$(MAKE) ARCH=arm OS=linux
